/* init.S -- AT91SAM7 rom init code
**
** Copyright 2006, Brian Swetland.  All rights reserved.     
** See provided LICENSE file or http://frotz.net/LICENSE for details.
*/

#include "../library/arm7.h"
		
.globl _start

#define TOP_OF_RAM       0x00204000

_start:
	b reset_handler
	b .                 /* undefine opcode */
	b .                 /* swi trap */
	b .                 /* prefetch abort */
	b .                 /* data abort */
	b .
	b .                 /* irq handler */

reset_handler:
	bl init_clock

bootloader_start:
	msr cpsr_c, #(PSR_I | PSR_F | PSR_SVC)
	ldr sp, =TOP_OF_RAM

init_bss:
	mov r0, #0
	ldr r1, =BSS_START
	ldr r2, =BSS_END
init_bss_loop:
	cmp r1, r2
	beq start
	str r0, [r1], #4
	b init_bss_loop

start:
/* enable the NRST reset pin */
	ldr r1, =0xfffffd08
	ldr r0, =0xa5000401
	str r0, [r1]

/* disable watchdog */
	ldr r1, =0xfffffd44
	ldr r0, =0x3fff8fff
	str r0, [r1]
		
	ldr r0, =boot
	bx r0

